package com.atguigu.func;

import com.atguigu.utils.DateFormatUtil;
import lombok.SneakyThrows;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

import java.lang.reflect.Field;

/**
 * ClassName: WindowFunction
 * Package: com.atguigu.func
 * Description:
 *
 * @Author Lovxy
 * @Create 2023/5/17 21:04
 * @Version 1.0
 */
public class WindowFuncUtil {
    @SneakyThrows
    public static <T>void setTes(TimeWindow window, Iterable<T> input, Collector<T> out){
        T next = input.iterator().next();

        Class<?> aClass = next.getClass();

        Field ts = aClass.getDeclaredField("ts");
        ts.setAccessible(true);
        ts.set(next,System.currentTimeMillis());

        Field stt = aClass.getDeclaredField("stt");
        stt.setAccessible(true);
        stt.set(next, DateFormatUtil.toYmdHms(window.getStart()));

        Field edt = aClass.getDeclaredField("edt");
        edt.setAccessible(true);
        edt.set(next,DateFormatUtil.toYmdHms(window.getEnd()));

        out.collect(next);


    }
}